package com.example.robotwatcher.backend;

import android.content.Context;

import org.bytedeco.ffmpeg.global.avutil;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;

public class VideoReceiver {
    String TargetAddress;
    FFmpegFrameGrabber FrameGrabber;
    boolean isWorking=false;
    public VideoReceiver() {

    }

    public void Init(String targetAddress) throws FFmpegFrameGrabber.Exception {
        FrameGrabber = FFmpegFrameGrabber.createDefault(targetAddress);
        FrameGrabber.setOption("rtsp_transport", "tcp");
        FrameGrabber.setOption("fflags", "nobuffer");

        FrameGrabber.setFrameRate(30);

        FrameGrabber.setPixelFormat(avutil.AV_PIX_FMT_RGBA);

    }

    public void Start() throws FFmpegFrameGrabber.Exception {
        FrameGrabber.start();
        isWorking = true;
    }
    public void Stop() throws FFmpegFrameGrabber.Exception {
        FrameGrabber.stop();
        isWorking = false;
    }

    public Frame GetImage() throws FFmpegFrameGrabber.Exception {
        Frame grabFrame = FrameGrabber.grab();
        return grabFrame;
    }

}
